package org.kymjs.kjframe.demo;

import com.yanzhenjie.andserver.annotation.GetMapping;
import com.yanzhenjie.andserver.annotation.RequestMapping;
import com.yanzhenjie.andserver.annotation.RequestParam;
import com.yanzhenjie.andserver.annotation.RestController;

@RestController
@RequestMapping("/")
class EnvController {

    @GetMapping("/connect")
    public boolean connect() {
        UsbManage.connect();
        return true;
    }
}

@RestController
@RequestMapping("/keyboard")
class KeyBoardController {

    @GetMapping("/paste")
    public boolean paste() {
        return UsbPlugins.paste();
    }

    @GetMapping("/copy")
    public boolean copy() {
        return UsbPlugins.copy();
    }

    @GetMapping("/home")
    public boolean home() {
        return UsbPlugins.home();
    }

    @GetMapping("/back")
    public boolean back() {
        return UsbPlugins.back();
    }

    @GetMapping("/enter")
    public boolean enter() {
        return UsbPlugins.enter();
    }

    @GetMapping("/recent")
    public boolean recent() {
        return UsbPlugins.recent();
    }

    @GetMapping("/write")
    public boolean write(
            @RequestParam("modifiers") String modifiers,
            @RequestParam("key") String key) {
        int modifiersInt = Integer.parseInt(modifiers.replace("0x", ""), 16);
        int keyInt = Integer.parseInt(key.replace("0x", ""), 16);
        return UsbPlugins.write(modifiersInt, keyInt);
    }
}

@RestController
@RequestMapping("/mouse")
class MouseController {

    @GetMapping("/click")
    public boolean click(
            @RequestParam("x") int x,
            @RequestParam("y") int y) {
        UsbManage.click((double) x, (double) y);
        return true;
    }

    @GetMapping("/swipe")
    public boolean swipe(
            @RequestParam("x") double x,
            @RequestParam("y") double y,
            @RequestParam("ex") double ex,
            @RequestParam("ey") double ey) {
        return UsbManage.swipe(x, y, ex, ey);
    }

    @GetMapping("/swipe1")
    public boolean swipe1(
            @RequestParam("x") double x,
            @RequestParam("y") double y,
            @RequestParam("ex") double ex,
            @RequestParam("ey") double ey,
            @RequestParam("s") double s) {
        return UsbManage.swipe1(x, y, ex, ey, s, 1000);
    }

    @GetMapping("/release")
    public boolean release() {
        return UsbManage.release();
    }

    @GetMapping("/press")
    public boolean press(
            @RequestParam("x") double x,
            @RequestParam("y") double y) {
        return UsbManage.press(x, y);
    }
}

